var surveyingCtl = require('../controller/controller.surveying.js');
var roadshowCtl = require('../controller/controller.roadshow.js');
var strategyCtl = require('../controller/controller.strategy-meeting.js');
var recommondCtl = require('../controller/controller.recommond.js');
var otherCtl = require('../controller/controller.other-service.js');
var sellerCtl = require('../controller/controller.seller.js');
var evaluateCtl = require('../controller/controller.evaluate.js')



module.exports = {
    getEvaluateSellerList: function (req, res, next) {

        var params = req.query;
        evaluateCtl.getCountList(params, function (err, result) {
            if (err) {
                res.redirect('/error');
                return;
            }
            next({'list': result.obj});
        })

    },

    getEvaluateServiceList: function (req, res, next) {


        var params = req.query;
        surveyingCtl.getListBySeller(params, function (err, resultSurveying) {
            if (err) {
                res.redirect('/error');
                return;
            }
            //查roadshow
            roadshowCtl.getListBySeller(params, function (err, resultRoadshow) {
                if (err) {
                    res.redirect('/error');
                    return;
                }
                //查strategy
                strategyCtl.getListBySeller(params, function (err, resultStrategy) {
                    if (err) {
                        res.redirect('/error');
                        return;
                    }
                    //查recommond
                    recommondCtl.getListBySeller(params, function (err, resultRecommond) {
                        if (err) {
                            res.redirect('/error');
                            return;
                        }
                        //查other
                        otherCtl.getListBySeller(params, function (err, resultOther) {
                            if (err) {
                                res.redirect('/error');
                                return;
                            }
                            next({
                                    'listSurveying': resultSurveying.obj,
                                    'listRoadshow': resultRoadshow.obj,
                                    'listStrategy': resultStrategy.obj,
                                    'listRecommond': resultRecommond.obj,
                                    'listOther': resultOther.obj,
                                    'seller' : params.seller,
                                    moment: require("moment")
                                }
                            );
                        })
                    })
                })
            })
        })
    },

    getEvaluateServiceListByType: function (req, res, next) {


        // var currentuid = 'c79a554d-1116-48c6-82ec-826be3d19551';
        var currentuid = req.session.uid;

        var params = req.query;
        switch (params.stype) {
            case "survey":
                surveyingCtl.getListBySeller(params, function(err, result) {
                    if(err){
                        res.redirect('/error');
                        return;
                    }
                    next({'list':result.obj,
                        'stype':"survey",
                        'uid':currentuid,
                        moment: require("moment")
                    });
                })
                break;

            case "roadshow":
                roadshowCtl.getListBySeller(params, function(err, result) {

                    if(err){
                        res.redirect('/error');
                        return;
                    }
                    next({'list':result.obj,
                        'stype':"roadshow",
                        'uid':currentuid,
                        moment: require("moment")
                    });
                })
                break;

            case "strategy":
                strategyCtl.getListBySeller(params, function(err, result) {
                    if(err){
                        res.redirect('/error');
                        return;
                    }
                    next({'list':result.obj,
                        'stype':"strategy",
                        'uid':currentuid,
                        moment: require("moment")
                    });
                })
                break;


            case "recommond":
                recommondCtl.getListBySeller(params, function(err, result) {
                    if(err){
                        res.redirect('/error');
                        return;
                    }
                    next({'list':result.obj,
                        'stype':"recommond",
                        'uid':currentuid,
                        moment: require("moment")
                    });
                })
                break;

            case "other":
                otherCtl.getListBySeller(params, function(err, result) {
                    if(err){
                        res.redirect('/error');
                        return;
                    }
                    next({'list':result.obj,
                        'stype':"other",
                        'uid':currentuid,
                        moment: require("moment")
                    });
                })
                break;

            default:
                console.log("getEvaluateServiceListByType:wrong param");
                res.redirect('/error');
                return;

        }
    },



    getEvaluateDetailInfo: function (req, res, next) {


        // var currentuid = "c79a554d-1116-48c6-82ec-826be3d19551";
        var currentuid = req.session.uid;

        var params = req.query;
        switch (params.stype) {
            case "survey":
                surveyingCtl.getInfo(params, function(err, result) {
                    if(err){
                        res.redirect('/error');
                        return;
                    }
                    next({'info':result.obj,
                            'stype':"survey",
                            'uid':currentuid,
                            moment: require("moment")
                    });
                })
                break;

            case "roadshow":
                roadshowCtl.getInfo(params, function(err, result) {

                    if(err){
                        res.redirect('/error');
                        return;
                    }
                    next({'info':result.obj,
                        'stype':"roadshow",
                        'uid':currentuid,
                        moment: require("moment")
                    });
                })
                break;

            case "strategy":
                strategyCtl.getInfo(params, function(err, result) {
                    if(err){
                        res.redirect('/error');
                        return;
                    }
                    next({'info':result.obj,
                        'stype':"strategy",
                        'uid':currentuid,
                        moment: require("moment")
                    });
                })
                break;


            case "recommond":
                recommondCtl.getInfo(params, function(err, result) {
                    if(err){
                        res.redirect('/error');
                        return;
                    }
                    next({'info':result.obj,
                        'stype':"recommond",
                        'uid':currentuid,
                        moment: require("moment")
                    });
                })
                break;

            case "other":
                otherCtl.getInfo(params, function(err, result) {
                    if(err){
                        res.redirect('/error');
                        return;
                    }
                    next({'info':result.obj,
                        'stype':"other",
                        'uid':currentuid,
                        moment: require("moment")
                    });
                })
                break;

            default:
                console.log("getEvaluateDetailInfo:wrong param");
                res.redirect('/error');
                return;

        }
    },


    updateScore: function (req, res, next) {

        var params = req.body;
        switch (params.stype) {
            case "survey":
                surveyingCtl.update(params, function(err, result) {
                    if(err){
                        res.redirect('/error');
                        return;
                    }
                    next({'result':result,
                        'stype':"survey"
                    });
                })
                break;

            case "roadshow":
                roadshowCtl.update(params, function(err, result) {
                    if(err){
                        res.redirect('/error');
                        return;
                    }
                    next({'result':result,
                        'stype':"roadshow"
                    });
                })
                break;

            case "strategy":
                strategyCtl.update(params, function(err, result) {
                    if(err){
                        res.redirect('/error');
                        return;
                    }
                    next({'result':result,
                        'stype':"strategy"
                    });
                })
                break;


            case "recommond":
                recommondCtl.update(params, function(err, result) {
                    if(err){
                        res.redirect('/error');
                        return;
                    }
                    next({'result':result,
                        'stype':"recommond"
                    });
                })
                break;

            case "other":
                otherCtl.update(params, function(err, result) {
                    if(err){
                        res.redirect('/error');
                        return;
                    }
                    next({'result':result,
                        'stype':"other"
                    });
                })
                break;

            default:
                console.log("updateScore:wrong param");
                res.redirect('/error');
                return;

        }
    },

    //根据sellerId获取统计信息
    getEvaluateInfo: function (req, res, next) {
        var params = req.query;
        //params.rowId=session.userInfo.seller;
        evaluateCtl.getCountById(params, function (err, result) {
            if (err) {
                res.redirect('/error');
                return;
            }
            next({
                'evaluate': result.obj
            });
        })

    },

    //根据sellerId获取统计信息
    getEvaluateInfoList: function (req, res, next) {
        var params = req.query;
        var role = req.session.userinfo.role;

        if (role != '4' && role == '5') {

            params.rowId=session.userInfo.seller;

        }
        evaluateCtl.getCountById(params, function (err, result) {
            if (err) {
                res.redirect('/error');
                return;
            }
            next({
                'evaluate': result.obj
            });
        })
    }


};
